//
//  NYNavigationController.m
//  百思不得姐
//
//  Created by Apple on 15/8/22.
//  Copyright (c) 2015年 Neal. All rights reserved.
//

#import "NYNavigationController.h"

@interface NYNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation NYNavigationController

+ (void)initialize
{
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
    [bar setTitleTextAttributes:attrs];
    
    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *normalattrs = [NSMutableDictionary dictionary];
    normalattrs[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    normalattrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:normalattrs forState:UIControlStateNormal];
    
    NSMutableDictionary *disattrs = [NSMutableDictionary dictionary];
    disattrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:disattrs forState:UIControlStateDisabled];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.interactivePopGestureRecognizer.delegate = self;
}
//push 控制器时隐藏状态栏
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [button setContentEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
        [button sizeToFit];
        [button addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    }
    
    [super pushViewController:viewController animated:animated];
}
- (void)backClick{
    [self popViewControllerAnimated:YES];
}
/**
 *监听系统滑动手势，如果需要保持系统滑动，在非跟控制器时的手势
 */
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return self.childViewControllers.count>1;
}
@end
